//
//  ALPS_RecommendTableViewCell.m
//  Alps
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_RecommendTableViewCell.h"

@implementation ALPS_RecommendTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, ScreeHeight / 6.67 - 20, ScreeHeight / 6.67 - 20)];
        [self.contentView addSubview:_leftImageView];
        
        self.finishImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _leftImageView.frame.size.width / 2, _leftImageView.frame.size.height / 2)];
        [self.leftImageView addSubview:_finishImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.numberOfLines = 2;
        [self.contentView addSubview:_titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(10, ScreeHeight / 6.67 , ScreeHeight / 6.67 - 40, 40));
        }];
        
        self.introLabel = [[UILabel alloc] init];
        self.introLabel.font = [UIFont systemFontOfSize:14];
        self.introLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_introLabel];
        [self.introLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 16.675, ScreeHeight / 6.67, ScreeHeight / 6.67 - ScreeHeight / 11.17, 40));
        }];
        
        self.playImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_playImageView];
        [self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 25, ScreeHeight / 6.67, 10, ScreeWidth - ScreeHeight / 6.67 - 15));
        }];
        
        self.playCountLabel = [[UILabel alloc] init];
        self.playCountLabel.font = [UIFont systemFontOfSize:14];
        self.playCountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_playCountLabel];
        [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 30, ScreeHeight / 6.67 + 15, 5, ScreeWidth / 1.97));
        }];
        
        self.numberImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_numberImageView];
        [self.numberImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 25, ScreeWidth / 1.97, 10, ScreeWidth - ScreeWidth / 1.83));
        }];
        
        self.numberLabel = [[UILabel alloc] init];
        self.numberLabel.textColor = [UIColor grayColor];
        self.numberLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_numberLabel];
        [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 30, ScreeWidth / 1.83, 5, 100));
        }];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
        [self.contentView addSubview:_lineLabel];
        [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(ScreeHeight / 6.67 - 1, 100, 0, 0));
        }];
    }
    return self;
}

- (void)setModel:(ALPS_MainModel *)model
{
    if (_model != model) {
        _model = model;
        [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.coverMiddle] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
        self.titleLabel.text = model.title;
        self.introLabel.text = model.intro;
        self.playImageView.image = [UIImage imageNamed:@"album_play"];
        if (model.playsCounts > 10000) {
            self.playCountLabel.text = [NSString stringWithFormat:@"%.1f万", model.playsCounts / 10000];
        } else {
            self.playCountLabel.text = [NSString stringWithFormat:@"%ld", (NSInteger)model.playsCounts];
        }
        self.numberImageView.image = [UIImage imageNamed:@"album_tracks"];
        self.numberLabel.text = [NSString stringWithFormat:@"%ld集", model.tracks];
    }
}

- (void)setRecommendModel:(ALPS_MainModel *)recommendModel
{
    if (_recommendModel != recommendModel) {
        _recommendModel = recommendModel;
        self.titleLabel.text = recommendModel.title;
        self.playImageView.image = [UIImage imageNamed:@"album_play"];
        
        //左侧图片及简介(作者)
        if (self.contentType == 1) {
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:recommendModel.albumCoverUrl290] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
            self.introLabel.text = recommendModel.intro;
            self.numberImageView.image = [UIImage imageNamed:@"album_tracks"];
            self.numberLabel.text = [NSString stringWithFormat:@"%ld集", recommendModel.tracksCounts];
        } else {
            self.leftImageView.layer.masksToBounds = YES;
            self.leftImageView.layer.cornerRadius = (ScreeHeight / 6.67 - 20) / 2;
            self.leftImageView.layer.borderWidth = 1;
            self.leftImageView.layer.borderColor = [UIColor colorWithRed:0.99 green:0.34 blue:0.15 alpha:1.00].CGColor;
            [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:recommendModel.coverSmall] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
            self.introLabel.text = [NSString stringWithFormat:@"by %@", recommendModel.nickname];
            self.numberImageView.image = [UIImage imageNamed:@"paycmt_reply"];
            self.numberLabel.text = [NSString stringWithFormat:@"%ld", recommendModel.commentsCounts];
        }
        
        //集数
        if (recommendModel.playsCounts > 10000) {
            self.playCountLabel.text = [NSString stringWithFormat:@"%.1f万", recommendModel.playsCounts / 10000];
        } else {
            self.playCountLabel.text = [NSString stringWithFormat:@"%ld", (NSInteger)recommendModel.playsCounts];
        }
        
        //判断完本
        if (_recommendModel.isFinished == 2) {
        self.finishImageView.image = [UIImage imageNamed:@"album_novel_finish"];
        }
        
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
